from src.modules.knowbase.repository.dao.kb_dao import KBDao
from core.config import settings
from ..Interface.kb_interface import IKbInterface
from ..Interface.file_interface import IFileInterface
import os




class KBService(IKbInterface):

    async def get_kb_list(self,user_id: str = None, keyword: str = None,
                          page: int = 1, page_size: int = 10) -> dict:
        return await KBDao.get_kb_list(user_id=user_id, keyword=keyword,
                                       page=page, page_size=page_size)


    async def create_kb(self,kb_name:str, user_id: str = None):
        kb_dir = os.path.join(settings.MEDIA_ROOT, kb_name)
        os.makedirs(kb_dir, exist_ok=True)
        result = await KBDao.create_kb(kb_name, user_id)
        return result
    

    async def delete_by_kb_id(self,kb_id: str):
        return await KBDao.delete_by_kb_id(kb_id)
